package org.liveboardgames.agricola.domain.player;

import java.util.Set;

import org.liveboardgames.agricola.domain.common.Peep;
import org.liveboardgames.agricola.domain.common.Target;
import org.liveboardgames.agricola.domain.farm.Farm;
import org.liveboardgames.agricola.model.enums.ColorEnum;
import org.liveboardgames.agricola.model.structure.Visitable;
import org.liveboardgames.agricola.model.structure.Visitor;

public class Player implements Target, Visitable {

  private Long id;

  private String name;

  private ColorEnum color;

  private boolean hasHarvested;

  private Farm farm;

  private Set<Peep> peeps;
  
  private Score score;

  /**
   * We do not want an external call to set the id of the game for us, but
   * rather let Hibernate handle it itself. At game creation, no ID is specified
   * on the Flex side. It thus default to 0, which causes an error.
   * 
   * @param id
   *          the {@link #id} to set
   */
  public void setId(Long id) {
    if (id != 0) {
      this.id = id;
    }
  }

  /**
   * @return the {@link #id}
   */
  public Long getId() {
    return id;
  }

  /**
   * @return the {@link #name}
   */
  public String getName() {
    return name;
  }

  /**
   * @param name
   *          the {@link #name} to set
   */
  public void setName(String name) {
    this.name = name;
  }

  /**
   * @return the {@link #color}
   */
  public ColorEnum getColor() {
    return color;
  }

  /**
   * @param color
   *          the {@link #color} to set
   */
  public void setColor(ColorEnum color) {
    this.color = color;
  }

  /**
   * @return the {@link #hasHarvested}
   */
  public boolean isHasHarvested() {
    return hasHarvested;
  }

  /**
   * @param hasHarvested
   *          the {@link #hasHarvested} to set
   */
  public void setHasHarvested(boolean hasHarvested) {
    this.hasHarvested = hasHarvested;
  }

  /**
   * @return the {@link #farm}
   */
  public Farm getFarm() {
    return farm;
  }

  /**
   * @param farm
   *          the {@link #farm} to set
   */
  public void setFarm(Farm farm) {
    this.farm = farm;
  }

  /**
   * @param peeps
   *          the {@link #peeps} to set
   */
  public void setPeeps(Set<Peep> peeps) {
    this.peeps = peeps;
  }

  /**
   * @return the {@link #peeps}
   */
  public Set<Peep> getPeeps() {
    return peeps;
  }

  public void setScore(Score score) {
    this.score = score;
  }

  public Score getScore() {
    return score;
  }

  @Override
  public String toString() {
    return "Player (" + name + ", " + color + ")";
  }

  public void acceptVisit(Visitor visitor) {
    visitor.visit(this);

    if (this.farm != null) {
      farm.acceptVisit(visitor);
    }
  }
}